/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.dto.EventDto;
import com.excesys.exsecs.om.entity.OmWEvent;
import com.excesys.exsecs.om.service.OmWEventService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 维保事件
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ommaintenanceevent")
@Tag(name = "事件表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmMaintenanceEventController {

	private final OmWEventService omWEventService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param omWEvent 事件
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	// @PreAuthorize("@pms.hasPermission('om_omwevent_get')" )
	public R getOmWEventPage(Page page, OmWEvent omWEvent) {
		return R.ok(omWEventService.getMaintenanceEventWithRelPage(page, omWEvent));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param omWEvent 事件
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/getPage")
	// @PreAuthorize("@pms.hasPermission('om_omwevent_get')" )
	public R getPage(Page page, OmWEvent omWEvent) {
		return R.ok(omWEventService.getMaintenancePage(page, omWEvent));
	}

	/**
	 * 通过typeName自动获取当前新的事件名称
	 * @param typeName
	 * @return R
	 */
	@Operation(summary = "通过typeName自动获取当前新的事件名称", description = "通过typeName自动获取当前新的事件名称")
	@GetMapping("/getCurrentEventNameSeq/{typeName}")
	// @PreAuthorize("@pms.hasPermission('om_omwevent_get')" )
	public R getCurrentEventNameSeq(@PathVariable("typeName") String typeName) {
		return R.ok(omWEventService.getCurrentEventNameSeq(typeName));
	}

	/**
	 * 通过id查询事件
	 * @param evId id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{evId}")
	// @PreAuthorize("@pms.hasPermission('om_omwevent_get')" )
	public R getById(@PathVariable("evId") Integer evId) {
		return R.ok(omWEventService.getById(evId));
	}

	/**
	 * 新增事件
	 * @param omWEvent 事件
	 * @return R
	 */
	@Operation(summary = "新增事件", description = "新增事件")
	@SysLog("新增事件")
	@PostMapping
	// @PreAuthorize("@pms.hasPermission('om_omwevent_add')" )
	public R save(@RequestBody EventDto omWEvent) {
		return R.ok(omWEventService.saveMaintenanceEvent(omWEvent));
	}

	/**
	 * 修改事件
	 * @param omWEvent 事件
	 * @return R
	 */
	@Operation(summary = "修改事件", description = "修改事件")
	@SysLog("修改事件")
	@PutMapping
	// @PreAuthorize("@pms.hasPermission('om_omwevent_edit')" )
	public R updateById(@RequestBody EventDto omWEvent) {

		return R.ok(omWEventService.updateEvent(omWEvent));
	}

	/**
	 * 通过id删除事件
	 * @param evId id
	 * @return R
	 */
	@Operation(summary = "通过id删除事件", description = "通过id删除事件")
	@SysLog("通过id删除事件")
	@DeleteMapping("/{evId}")
	// @PreAuthorize("@pms.hasPermission('om_omwevent_del')" )
	public R removeById(@PathVariable Integer evId) {
		return R.ok(omWEventService.removeById(evId));
	}

	/**
	 * 操作事件
	 * @param eventDto 事件
	 * @return R
	 */
	@Operation(summary = "操作事件", description = "操作事件")
	@SysLog("操作事件")
	@PostMapping("/operate")
	// @PreAuthorize("@pms.hasPermission('om_omworder_add')" )
	public R operateOmWOrder(@RequestBody EventDto eventDto) {
		return R.ok(omWEventService.operateOmMaintenanceEvent(eventDto));
	}

	/**
	 * 删除多个投诉
	 * @param idList 删除多个投诉
	 * @return R
	 */
	@Operation(summary = "删除多个巡检点", description = "删除多个巡检点")
	@SysLog("删除多个巡检点")
	@DeleteMapping("/removeByIds")
	// @PreAuthorize("@pms.hasPermission('om_omicheckpoint_del')")
	public R removeByIds(@RequestBody List<Integer> idList) {
		return R.ok(omWEventService.removeByIds(idList));
	}

}
